package Test2;

import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class MyJFrame3 extends JFrame implements KeyListener {
    JButton jtb1 =new JButton("点我呀！");

    {
        this.setSize(600, 800);
        this.setTitle("登录");
        this.setAlwaysOnTop(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setLayout(null);
        this.setVisible(true);

        jtb1.setBounds(0, 0, 100, 50);
        //给按钮绑定鼠标事件
        jtb1.addKeyListener(this);

        this.getContentPane().add(jtb1);
        this.setVisible(true);
    }


    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {
        System.out.println("按下了");
    }

    @Override
    public void keyReleased(KeyEvent e) {
        System.out.println("抬起了");
        int code = e.getKeyCode();
        if(code == 65)
        {
            System.out.println("按下了A");
        }
        else if(code == 66)
        {
            System.out.println("按下了B");
        }

    }
}
